package com.shelpe.services.sinbad.dto;

import org.apache.commons.lang3.math.NumberUtils;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.sinbad.service.simbaproxy.SimbaProxyBaseDto;
import com.shelpe.services.sinbad.service.simbaproxy.UserClient.GetRtrCustDto;
import com.shelpe.services.sinbad.utils.DateUtil;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class EffectMetricDto extends SimbaProxyBaseDto {

	@JsonProperty("direct_transaction")
	private int directTransaction;// 直接成交金额
	@JsonProperty("indirect_transaction")
	private int indirectTransaction;// 间接成交金额
	@JsonProperty("direct_transaction_shipping")
	private int directTransactionShipping;// 直接成交笔数
	@JsonProperty("indirect_transaction_shipping")
	private int indirectTransactionShipping;// 间接成交笔数
	@JsonProperty("fav_item_total")
	private int favItemTotal;// 宝贝收藏数
	@JsonProperty("fav_shop_total")
	private int favShopTotal;// 店铺收藏数
	@JsonProperty("fav_total")
	private int favTotal;// 总收藏数
	@JsonProperty("pay_total_count")
	private int transactionShippingTotal;// 总成交笔数
	@JsonProperty("sale")
	private int transactionTotal;// 总成交金额
	@JsonProperty("direct_cart_total")
	private int directCartTotal;// 直接购物车数
	@JsonProperty("indirect_cart_total")
	private int indirectCartTotal;// 间接购物车数
	@JsonProperty("cart_total")
	private int cartTotal; // 购物车总数

	private int impressions;// 展现量
	private int click;// 点击量
	private int cost;// 花费（分）

	private float roi;// 投入产出比
	@JsonProperty("cvr")
	private float coverage;// 点击转化率
	private float ctr;// 点击率
	private float cpc;// 平均点击花费
	private float cpm;

	public void from(GetRtrCustDto res) {
		this.directTransaction = (int) NumberUtils.toFloat(res.getDirectTransaction());
		this.indirectTransaction = (int) NumberUtils.toFloat(res.getIndirectTransaction());
		this.directTransactionShipping = NumberUtils.toInt(res.getDirectTransactionShipping());
		this.indirectTransactionShipping = NumberUtils.toInt(res.getIndirectTransactionShipping());
		this.favItemTotal = NumberUtils.toInt(res.getFavItemTotal());
		this.favShopTotal = NumberUtils.toInt(res.getFavShopTotal());
		this.favTotal = NumberUtils.toInt(res.getFavTotal());
		this.transactionShippingTotal = NumberUtils.toInt(res.getTransactionShippingTotal());
		this.transactionTotal = (int) NumberUtils.toFloat(res.getTransactionTotal());
		this.directCartTotal = NumberUtils.toInt(res.getDirectCartTotal());
		this.indirectCartTotal = NumberUtils.toInt(res.getIndirectCartTotal());
		this.cartTotal = NumberUtils.toInt(res.getCartTotal());
		this.impressions = NumberUtils.toInt(res.getImpression());
		this.click = NumberUtils.toInt(res.getClick());
		this.cost = NumberUtils.toInt(res.getCost());

		this.roi = NumberUtils.toFloat(res.getRoi());
		this.coverage = (float) DateUtil.formatDouble2((double) 100 * this.transactionShippingTotal / this.click);// 直接加百分号
		this.ctr = (float) DateUtil.formatDouble2(NumberUtils.toDouble(res.getCtr()));// 直接加百分号
		this.cpc = (float) DateUtil.formatDouble2(NumberUtils.toDouble(res.getCpc()) / 100);// 单位元
		this.cpm = NumberUtils.toFloat(res.getCpm());

	}
}
